home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / gdb / valprint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-29  |  57.1 KB  |  2,134 lines

  1. /* Print values for GDB, the GNU debugger.
  2.    Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include <string.h>
  22. #include "symtab.h"
  23. #include "gdbtypes.h"
  24. #include "value.h"
  25. #include "gdbcore.h"
  26. #include "gdbcmd.h"
  27. #include "target.h"
  28. #include "obstack.h"
  29. #include "language.h"
  30.  
  31. #include <errno.h>
  32.  
  33. /* Prototypes for local functions */
  34.  
  35. static void
  36. print_string PARAMS ((FILE *, char *, unsigned int, int));
  37.  
  38. static void
  39. show_print PARAMS ((char *, int));
  40.  
  41. static void
  42. set_print PARAMS ((char *, int));
  43.  
  44. static void
  45. set_radix PARAMS ((char *, int, struct cmd_list_element *));
  46.  
  47. static void
  48. set_output_radix PARAMS ((char *, int, struct cmd_list_element *));
  49.  
  50. static void
  51. type_print_base PARAMS ((struct type *, FILE *, int, int));
  52.  
  53. static void
  54. type_print_varspec_suffix PARAMS ((struct type *, FILE *, int, int));
  55.  
  56. static void
  57. type_print_varspec_prefix PARAMS ((struct type *, FILE *, int, int));
  58.  
  59. static void
  60. type_print_derivation_info PARAMS ((FILE *, struct type *));
  61.  
  62. static void
  63. type_print_method_args PARAMS ((struct type **, char *, char *, int, FILE *));
  64.  
  65. static void
  66. cplus_val_print PARAMS ((struct type *, char *, FILE *, int, int,
  67.              enum val_prettyprint, struct type **));
  68.  
  69. static void
  70. val_print_fields PARAMS ((struct type *, char *, FILE *, int, int,
  71.               enum val_prettyprint, struct type **));
  72.  
  73. static int
  74. is_vtbl_member PARAMS ((struct type *));
  75.  
  76. static int
  77. is_vtbl_ptr_type PARAMS ((struct type *));
  78.  
  79. static void
  80. print_hex_chars PARAMS ((FILE *, unsigned char *, unsigned));
  81.  
  82. extern int sys_nerr;
  83. extern char *sys_errlist[];
  84.  
  85. extern int demangle;    /* whether to print C++ syms raw or source-form */
  86.  
  87. /* Maximum number of chars to print for a string pointer value
  88.    or vector contents, or UINT_MAX for no limit.  */
  89.  
  90. static unsigned int print_max;
  91.  
  92. /* Default input and output radixes, and output format letter.  */
  93.  
  94. unsigned input_radix = 10;
  95. unsigned output_radix = 10;
  96. int output_format = 0;
  97.  
  98.  
  99. char **unsigned_type_table;
  100. char **signed_type_table;
  101. char **float_type_table;
  102.  
  103.  
  104. /* Print repeat counts if there are more than this
  105.    many repetitions of an element in an array.  */
  106. #define    REPEAT_COUNT_THRESHOLD    10
  107.  
  108. /* Define a mess of print controls.  */
  109.  
  110. int prettyprint;    /* Controls pretty printing of structures */
  111. int vtblprint;        /* Controls printing of vtbl's */
  112. int unionprint;        /* Controls printing of nested unions.  */
  113. int arrayprint;        /* Controls pretty printing of arrays.  */
  114. int addressprint;    /* Controls pretty printing of addresses.  */
  115. int objectprint;    /* Controls looking up an object's derived type
  116.                using what we find in its vtables.  */
  117.  
  118. struct obstack dont_print_obstack;
  119.  
  120.  
  121. /* Print the character string STRING, printing at most LENGTH characters.
  122.    Printing stops early if the number hits print_max; repeat counts
  123.    are printed as appropriate.  Print ellipses at the end if we
  124.    had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.  */
  125.  
  126. static void
  127. print_string (stream, string, length, force_ellipses)
  128.      FILE *stream;
  129.      char *string;
  130.      unsigned int length;
  131.      int force_ellipses;
  132. {
  133.   register unsigned int i;
  134.   unsigned int things_printed = 0;
  135.   int in_quotes = 0;
  136.   int need_comma = 0;
  137.   extern int inspect_it;
  138.  
  139.   if (length == 0)
  140.     {
  141.       fputs_filtered ("\"\"", stdout);
  142.       return;
  143.     }
  144.  
  145.   for (i = 0; i < length && things_printed < print_max; ++i)
  146.     {
  147.       /* Position of the character we are examining
  148.      to see whether it is repeated.  */
  149.       unsigned int rep1;
  150.       /* Number of repetitions we have detected so far.  */
  151.       unsigned int reps;
  152.  
  153.       QUIT;
  154.  
  155.       if (need_comma)
  156.     {
  157.       fputs_filtered (", ", stream);
  158.       need_comma = 0;
  159.     }
  160.  
  161.       rep1 = i + 1;
  162.       reps = 1;
  163.       while (rep1 < length && string[rep1] == string[i])
  164.     {
  165.       ++rep1;
  166.       ++reps;
  167.     }
  168.  
  169.       if (reps > REPEAT_COUNT_THRESHOLD)
  170.     {
  171.       if (in_quotes)
  172.         {
  173.           if (inspect_it)
  174.         fputs_filtered ("\\\", ", stream);
  175.           else
  176.         fputs_filtered ("\", ", stream);
  177.           in_quotes = 0;
  178.         }
  179.       fputs_filtered ("'", stream);
  180.       printchar (string[i], stream, '\'');
  181.       fprintf_filtered (stream, "' <repeats %u times>", reps);
  182.       i = rep1 - 1;
  183.       things_printed += REPEAT_COUNT_THRESHOLD;
  184.       need_comma = 1;
  185.     }
  186.       else
  187.     {
  188.       if (!in_quotes)
  189.         {
  190.           if (inspect_it)
  191.         fputs_filtered ("\\\"", stream);
  192.           else
  193.         fputs_filtered ("\"", stream);
  194.           in_quotes = 1;
  195.         }
  196.       printchar (string[i], stream, '"');
  197.       ++things_printed;
  198.     }
  199.     }
  200.  
  201.   /* Terminate the quotes if necessary.  */
  202.   if (in_quotes)
  203.     {
  204.       if (inspect_it)
  205.     fputs_filtered ("\\\"", stream);
  206.       else
  207.     fputs_filtered ("\"", stream);
  208.     }
  209.  
  210.   if (force_ellipses || i < length)
  211.     fputs_filtered ("...", stream);
  212. }
  213.  
  214. /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
  215.    on STREAM.  */
  216.  
  217. void
  218. print_floating (valaddr, type, stream)
  219.      char *valaddr;
  220.      struct type *type;
  221.      FILE *stream;
  222. {
  223.   double doub;
  224.   int inv;
  225.   unsigned len = TYPE_LENGTH (type);
  226.   
  227. #if defined (IEEE_FLOAT)
  228.  
  229.   /* Check for NaN's.  Note that this code does not depend on us being
  230.      on an IEEE conforming system.  It only depends on the target
  231.      machine using IEEE representation.  This means (a)
  232.      cross-debugging works right, and (2) IEEE_FLOAT can (and should)
  233.      be defined for systems like the 68881, which uses IEEE
  234.      representation, but is not IEEE conforming.  */
  235.  
  236.   {
  237.     long low, high;
  238.     /* Is the sign bit 0?  */
  239.     int nonnegative;
  240.     /* Is it is a NaN (i.e. the exponent is all ones and
  241.        the fraction is nonzero)?  */
  242.     int is_nan;
  243.  
  244.     if (len == sizeof (float))
  245.       {
  246.     /* It's single precision. */
  247.     bcopy (valaddr, &low, sizeof (low));
  248.     /* target -> host.  */
  249.     SWAP_TARGET_AND_HOST (&low, sizeof (float));
  250.     nonnegative = low >= 0;
  251.     is_nan = ((((low >> 23) & 0xFF) == 0xFF) 
  252.           && 0 != (low & 0x7FFFFF));
  253.     low &= 0x7fffff;
  254.     high = 0;
  255.       }
  256.     else
  257.       {
  258.     /* It's double precision.  Get the high and low words.  */
  259.  
  260. #if TARGET_BYTE_ORDER == BIG_ENDIAN
  261.       bcopy (valaddr+4, &low,  sizeof (low));
  262.       bcopy (valaddr+0, &high, sizeof (high));
  263. #else
  264.       bcopy (valaddr+0, &low,  sizeof (low));
  265.       bcopy (valaddr+4, &high, sizeof (high));
  266. #endif
  267.       SWAP_TARGET_AND_HOST (&low, sizeof (low));
  268.       SWAP_TARGET_AND_HOST (&high, sizeof (high));
  269.       nonnegative = high >= 0;
  270.       is_nan = (((high >> 20) & 0x7ff) == 0x7ff
  271.             && ! ((((high & 0xfffff) == 0)) && (low == 0)));
  272.       high &= 0xfffff;
  273.     }
  274.  
  275.     if (is_nan)
  276.       {
  277.     /* The meaning of the sign and fraction is not defined by IEEE.
  278.        But the user might know what they mean.  For example, they
  279.        (in an implementation-defined manner) distinguish between
  280.        signaling and quiet NaN's.  */
  281.     if (high)
  282.       fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonnegative,
  283.                 high, low);
  284.     else
  285.       fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low);
  286.     return;
  287.       }
  288.   }
  289. #endif /* IEEE_FLOAT.  */
  290.  
  291.   doub = unpack_double (type, valaddr, &inv);
  292.   if (inv)
  293.     fprintf_filtered (stream, "<invalid float value>");
  294.   else
  295.     fprintf_filtered (stream, len <= sizeof(float) ? "%.9g" : "%.17g", doub);
  296. }
  297.  
  298. /* VALADDR points to an integer of LEN bytes.  Print it in hex on stream.  */
  299. static void
  300. print_hex_chars (stream, valaddr, len)
  301.      FILE *stream;
  302.      unsigned char *valaddr;
  303.      unsigned len;
  304. {
  305.   unsigned char *p;
  306.   
  307.   fprintf_filtered (stream, "0x");
  308. #if TARGET_BYTE_ORDER == BIG_ENDIAN
  309.   for (p = valaddr;
  310.        p < valaddr + len;
  311.        p++)
  312. #else /* Little endian.  */
  313.   for (p = valaddr + len - 1;
  314.        p >= valaddr;
  315.        p--)
  316. #endif
  317.     {
  318.       fprintf_filtered (stream, "%02x", *p);
  319.     }
  320. }
  321.  
  322. /* Print the value VAL in C-ish syntax on stream STREAM.
  323.    FORMAT is a format-letter, or 0 for print in natural format of data type.
  324.    If the object printed is a string pointer, returns
  325.    the number of string bytes printed.  */
  326.  
  327. int
  328. value_print (val, stream, format, pretty)
  329.      value val;
  330.      FILE *stream;
  331.      int format;
  332.      enum val_prettyprint pretty;
  333. {
  334.   register unsigned int i, n, typelen;
  335.  
  336.   if (val == 0)
  337.     {
  338.       printf_filtered ("<address of value unknown>");
  339.       return 0;
  340.     }
  341.   if (VALUE_OPTIMIZED_OUT (val))
  342.     {
  343.       printf_filtered ("<value optimized out>");
  344.       return 0;
  345.     }
  346.  
  347.   /* A "repeated" value really contains several values in a row.
  348.      They are made by the @ operator.
  349.      Print such values as if they were arrays.  */
  350.  
  351.   else if (VALUE_REPEATED (val))
  352.     {
  353.       n = VALUE_REPETITIONS (val);
  354.       typelen = TYPE_LENGTH (VALUE_TYPE (val));
  355.       fprintf_filtered (stream, "{");
  356.       /* Print arrays of characters using string syntax.  */
  357.       if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
  358.       && format == 0)
  359.     print_string (stream, VALUE_CONTENTS (val), n, 0);
  360.       else
  361.     {
  362.       unsigned int things_printed = 0;
  363.       
  364.       for (i = 0; i < n && things_printed < print_max; i++)
  365.         {
  366.           /* Position of the array element we are examining to see
  367.          whether it is repeated.  */
  368.           unsigned int rep1;
  369.           /* Number of repetitions we have detected so far.  */
  370.           unsigned int reps;
  371.  
  372.           if (i != 0)
  373.         fprintf_filtered (stream, ", ");
  374.           wrap_here ("");
  375.  
  376.           rep1 = i + 1;
  377.           reps = 1;
  378.           while (rep1 < n
  379.              && !bcmp (VALUE_CONTENTS (val) + typelen * i,
  380.                    VALUE_CONTENTS (val) + typelen * rep1, typelen))
  381.         {
  382.           ++reps;
  383.           ++rep1;
  384.         }
  385.  
  386.           if (reps > REPEAT_COUNT_THRESHOLD)
  387.         {
  388.           val_print (VALUE_TYPE (val),
  389.                  VALUE_CONTENTS (val) + typelen * i,
  390.                  VALUE_ADDRESS (val) + typelen * i,
  391.                  stream, format, 1, 0, pretty);
  392.           fprintf (stream, " <repeats %u times>", reps);
  393.           i = rep1 - 1;
  394.           things_printed += REPEAT_COUNT_THRESHOLD;
  395.         }
  396.           else
  397.         {
  398.           val_print (VALUE_TYPE (val),
  399.                  VALUE_CONTENTS (val) + typelen * i,
  400.                  VALUE_ADDRESS (val) + typelen * i,
  401.                  stream, format, 1, 0, pretty);
  402.           things_printed++;
  403.         }
  404.         }
  405.       if (i < n)
  406.         fprintf_filtered (stream, "...");
  407.     }
  408.       fprintf_filtered (stream, "}");
  409.       return n * typelen;
  410.     }
  411.   else
  412.     {
  413.       struct type *type = VALUE_TYPE (val);
  414.  
  415.       /* If it is a pointer, indicate what it points to.
  416.  
  417.      Print type also if it is a reference.
  418.  
  419.          C++: if it is a member pointer, we will take care
  420.      of that when we print it.  */
  421.       if (TYPE_CODE (type) == TYPE_CODE_PTR
  422.       || TYPE_CODE (type) == TYPE_CODE_REF)
  423.     {
  424.       /* Hack:  remove (char *) for char strings.  Their
  425.          type is indicated by the quoted string anyway. */
  426.           if (TYPE_CODE (type) == TYPE_CODE_PTR
  427.           && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == sizeof(char)
  428.           && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_INT
  429.           && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
  430.         {
  431.         /* Print nothing */
  432.         }
  433.       else
  434.         {
  435.           fprintf_filtered (stream, "(");
  436.           type_print (type, "", stream, -1);
  437.           fprintf_filtered (stream, ") ");
  438.         }
  439.     }
  440.       return val_print (type, VALUE_CONTENTS (val),
  441.             VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
  442.     }
  443. }
  444.  
  445. /* Return truth value for assertion that TYPE is of the type
  446.    "pointer to virtual function".  */
  447. static int
  448. is_vtbl_ptr_type(type)
  449.      struct type *type;
  450. {
  451.   char *typename = type_name_no_tag (type);
  452.   static const char vtbl_ptr_name[] =
  453.     { CPLUS_MARKER,'v','t','b','l','_','p','t','r','_','t','y','p','e', 0 };
  454.  
  455.   return (typename != NULL && !strcmp(typename, vtbl_ptr_name));
  456. }
  457.  
  458. /* Return truth value for the assertion that TYPE is of the type
  459.    "pointer to virtual function table".  */
  460. static int
  461. is_vtbl_member(type)
  462.      struct type *type;
  463. {
  464.   if (TYPE_CODE (type) == TYPE_CODE_PTR)
  465.     type = TYPE_TARGET_TYPE (type);
  466.   else
  467.     return 0;
  468.  
  469.   if (TYPE_CODE (type) == TYPE_CODE_ARRAY
  470.       && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT)
  471.     /* Virtual functions tables are full of pointers to virtual functions.  */
  472.     return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type));
  473.   return 0;
  474. }
  475.  
  476. /* Mutually recursive subroutines of cplus_val_print and val_print to print out
  477.    a structure's fields: val_print_fields and cplus_val_print.
  478.  
  479.    TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
  480.    same meanings as in cplus_val_print and val_print.
  481.  
  482.    DONT_PRINT is an array of baseclass types that we
  483.    should not print, or zero if called from top level.  */
  484.  
  485. static void
  486. val_print_fields (type, valaddr, stream, format, recurse, pretty, dont_print)
  487.      struct type *type;
  488.      char *valaddr;
  489.      FILE *stream;
  490.      int format;
  491.      int recurse;
  492.      enum val_prettyprint pretty;
  493.      struct type **dont_print;
  494. {
  495.   int i, len, n_baseclasses;
  496.  
  497.   check_stub_type (type);
  498.  
  499.   fprintf_filtered (stream, "{");
  500.   len = TYPE_NFIELDS (type);
  501.   n_baseclasses = TYPE_N_BASECLASSES (type);
  502.  
  503.   /* Print out baseclasses such that we don't print
  504.      duplicates of virtual baseclasses.  */
  505.   if (n_baseclasses > 0)
  506.     cplus_val_print (type, valaddr, stream, format, recurse+1, pretty, dont_print);
  507.  
  508.   if (!len && n_baseclasses == 1)
  509.     fprintf_filtered (stream, "<No data fields>");
  510.   else
  511.     {
  512.       extern int inspect_it;
  513.       int fields_seen = 0;
  514.  
  515.       for (i = n_baseclasses; i < len; i++)
  516.     {
  517.       /* Check if static field */
  518.       if (TYPE_FIELD_STATIC (type, i))
  519.         continue;
  520.       if (fields_seen)
  521.         fprintf_filtered (stream, ", ");
  522.       else if (n_baseclasses > 0)
  523.         {
  524.           fprintf_filtered (stream, "\n");
  525.           print_spaces_filtered (2 + 2 * recurse, stream);
  526.           fputs_filtered ("members of ", stream);
  527.           fputs_filtered (type_name_no_tag (type), stream);
  528.           fputs_filtered (": ", stream);
  529.         }
  530.       fields_seen = 1;
  531.  
  532.       if (pretty)
  533.         {
  534.           fprintf_filtered (stream, "\n");
  535.           print_spaces_filtered (2 + 2 * recurse, stream);
  536.         }
  537.       else 
  538.         {
  539.           wrap_here (n_spaces (2 + 2 * recurse));
  540.         }
  541.       if (inspect_it)
  542.         {
  543.           if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
  544.         fputs_filtered ("\"( ptr \"", stream);
  545.           else
  546.         fputs_filtered ("\"( nodef \"", stream);
  547.           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  548.           fputs_filtered ("\" \"", stream);
  549.           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  550.           fputs_filtered ("\") \"", stream);
  551.         }
  552.       else
  553.         {
  554.           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  555.           fputs_filtered (" = ", stream);
  556.         }
  557.       if (TYPE_FIELD_PACKED (type, i))
  558.         {
  559.           value v;
  560.  
  561.           /* Bitfields require special handling, especially due to byte
  562.          order problems.  */
  563.           v = value_from_longest (TYPE_FIELD_TYPE (type, i),
  564.                    unpack_field_as_long (type, valaddr, i));
  565.  
  566.           val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
  567.              stream, format, 0, recurse + 1, pretty);
  568.         }
  569.       else
  570.         {
  571.           val_print (TYPE_FIELD_TYPE (type, i), 
  572.              valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
  573.              0, stream, format, 0, recurse + 1, pretty);
  574.         }
  575.     }
  576.       if (pretty)
  577.     {
  578.       fprintf_filtered (stream, "\n");
  579.       print_spaces_filtered (2 * recurse, stream);
  580.     }
  581.     }
  582.   fprintf_filtered (stream, "}");
  583. }
  584.  
  585. /* Special val_print routine to avoid printing multiple copies of virtual
  586.    baseclasses.  */
  587.  
  588. static void
  589. cplus_val_print (type, valaddr, stream, format, recurse, pretty, dont_print)
  590.      struct type *type;
  591.      char *valaddr;
  592.      FILE *stream;
  593.      int format;
  594.      int recurse;
  595.      enum val_prettyprint pretty;
  596.      struct type **dont_print;
  597. {
  598.   struct obstack tmp_obstack;
  599.   struct type **last_dont_print
  600.     = (struct type **)obstack_next_free (&dont_print_obstack);
  601.   int i, n_baseclasses = TYPE_N_BASECLASSES (type);
  602.  
  603.   if (dont_print == 0)
  604.     {
  605.       /* If we're at top level, carve out a completely fresh
  606.      chunk of the obstack and use that until this particular
  607.      invocation returns.  */
  608.       tmp_obstack = dont_print_obstack;
  609.       /* Bump up the high-water mark.  Now alpha is omega.  */
  610.       obstack_finish (&dont_print_obstack);
  611.     }
  612.  
  613.   for (i = 0; i < n_baseclasses; i++)
  614.     {
  615.       char *baddr;
  616.       int err;
  617.  
  618.       if (BASETYPE_VIA_VIRTUAL (type, i))
  619.     {
  620.       struct type **first_dont_print
  621.         = (struct type **)obstack_base (&dont_print_obstack);
  622.  
  623.       int j = (struct type **)obstack_next_free (&dont_print_obstack)
  624.         - first_dont_print;
  625.  
  626.       while (--j >= 0)
  627.         if (TYPE_BASECLASS (type, i) == first_dont_print[j])
  628.           goto flush_it;
  629.  
  630.       obstack_ptr_grow (&dont_print_obstack, TYPE_BASECLASS (type, i));
  631.     }
  632.  
  633.       baddr = baseclass_addr (type, i, valaddr, 0, &err);
  634.       if (err == 0 && baddr == 0)
  635.     error ("could not find virtual baseclass `%s'\n",
  636.            type_name_no_tag (TYPE_BASECLASS (type, i)));
  637.  
  638.       fprintf_filtered (stream, "\n");
  639.       if (pretty)
  640.     print_spaces_filtered (2 + 2 * recurse, stream);
  641.       fputs_filtered ("<", stream);
  642.       fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type, i)), stream);
  643.       fputs_filtered ("> = ", stream);
  644.       if (err != 0)
  645.     fprintf_filtered (stream, "<invalid address 0x%x>", baddr);
  646.       else
  647.     val_print_fields (TYPE_BASECLASS (type, i), baddr, stream, format,
  648.               recurse, pretty,
  649.               (struct type **)obstack_base (&dont_print_obstack));
  650.     flush_it:
  651.       ;
  652.     }
  653.  
  654.   if (dont_print == 0)
  655.     {
  656.       /* Free the space used to deal with the printing
  657.      of this type from top level.  */
  658.       obstack_free (&dont_print_obstack, last_dont_print);
  659.       /* Reset watermark so that we can continue protecting
  660.      ourselves from whatever we were protecting ourselves.  */
  661.       dont_print_obstack = tmp_obstack;
  662.     }
  663. }
  664.  
  665. static void
  666. print_class_member (valaddr, domain, stream, prefix)
  667.      char *valaddr;
  668.      struct type *domain;
  669.      FILE *stream;
  670.      char *prefix;
  671. {
  672.   
  673.   /* VAL is a byte offset into the structure type DOMAIN.
  674.      Find the name of the field for that offset and
  675.      print it.  */
  676.   int extra = 0;
  677.   int bits = 0;
  678.   register unsigned int i;
  679.   unsigned len = TYPE_NFIELDS (domain);
  680.   /* @@ Make VAL into bit offset */
  681.   LONGEST val = unpack_long (builtin_type_int, valaddr) << 3;
  682.   for (i = TYPE_N_BASECLASSES (domain); i < len; i++)
  683.     {
  684.       int bitpos = TYPE_FIELD_BITPOS (domain, i);
  685.       QUIT;
  686.       if (val == bitpos)
  687.     break;
  688.       if (val < bitpos && i != 0)
  689.     {
  690.       /* Somehow pointing into a field.  */
  691.       i -= 1;
  692.       extra = (val - TYPE_FIELD_BITPOS (domain, i));
  693.       if (extra & 0x7)
  694.         bits = 1;
  695.       else
  696.         extra >>= 3;
  697.       break;
  698.     }
  699.     }
  700.   if (i < len)
  701.     {
  702.       char *name;
  703.       fprintf_filtered (stream, prefix);
  704.       name = type_name_no_tag (domain);
  705.       if (name)
  706.         fputs_filtered (name, stream);
  707.       else
  708.     type_print_base (domain, stream, 0, 0);
  709.       fprintf_filtered (stream, "::");
  710.       fputs_filtered (TYPE_FIELD_NAME (domain, i), stream);
  711.       if (extra)
  712.     fprintf_filtered (stream, " + %d bytes", extra);
  713.       if (bits)
  714.     fprintf_filtered (stream, " (offset in bits)");
  715.     }
  716.   else
  717.     fprintf_filtered (stream, "%d", val >> 3);
  718. }
  719.  
  720. /* Print data of type TYPE located at VALADDR (within GDB),
  721.    which came from the inferior at address ADDRESS,
  722.    onto stdio stream STREAM according to FORMAT
  723.    (a letter or 0 for natural format).  The data at VALADDR
  724.    is in target byte order.
  725.  
  726.    If the data are a string pointer, returns the number of
  727.    sting characters printed.
  728.  
  729.    if DEREF_REF is nonzero, then dereference references,
  730.    otherwise just print them like pointers.
  731.  
  732.    The PRETTY parameter controls prettyprinting.  */
  733.  
  734. int
  735. val_print (type, valaddr, address, stream, format, deref_ref, recurse, pretty)
  736.      struct type *type;
  737.      char *valaddr;
  738.      CORE_ADDR address;
  739.      FILE *stream;
  740.      int format;
  741.      int deref_ref;
  742.      int recurse;
  743.      enum val_prettyprint pretty;
  744. {
  745.   register unsigned int i;
  746.   unsigned len;
  747.   struct type *elttype;
  748.   unsigned eltlen;
  749.   LONGEST val;
  750.   unsigned char c;
  751.  
  752.   if (pretty == Val_pretty_default)
  753.     {
  754.       pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint;
  755.     }
  756.   
  757.   QUIT;
  758.  
  759.   check_stub_type (type);
  760.   
  761.   if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
  762.     {
  763.       fprintf_filtered (stream, "<unknown struct>");
  764.       fflush (stream);
  765.       return 0;
  766.     }
  767.   
  768.   switch (TYPE_CODE (type))
  769.     {
  770.     case TYPE_CODE_ARRAY:
  771.       if (TYPE_LENGTH (type) > 0
  772.       && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
  773.     {
  774.       elttype = TYPE_TARGET_TYPE (type);
  775.       eltlen = TYPE_LENGTH (elttype);
  776.       len = TYPE_LENGTH (type) / eltlen;
  777.       if (arrayprint)
  778.         print_spaces_filtered (2 + 2 * recurse, stream);
  779.       fprintf_filtered (stream, "{");
  780.       /* For an array of chars, print with string syntax.  */
  781.       if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
  782.           && (format == 0 || format == 's') )
  783.         print_string (stream, valaddr, len, 0);
  784.       else
  785.         {
  786.           unsigned int things_printed = 0;
  787.           
  788.           /* If this is a virtual function table, print the 0th
  789.          entry specially, and the rest of the members normally.  */
  790.           if (is_vtbl_ptr_type (elttype))
  791.         {
  792.           fprintf_filtered (stream, "%d vtable entries", len-1);
  793.           i = 1;
  794.         }
  795.           else
  796.         i = 0;
  797.  
  798.           for (; i < len && things_printed < print_max; i++)
  799.         {
  800.           /* Position of the array element we are examining to see
  801.              whether it is repeated.  */
  802.           unsigned int rep1;
  803.           /* Number of repetitions we have detected so far.  */
  804.           unsigned int reps;
  805.           
  806.           if (i != 0)
  807.             if (arrayprint)
  808.               {
  809.                 fprintf_filtered (stream, ",\n");
  810.                     print_spaces_filtered (2 + 2 * recurse, stream);
  811.               }
  812.             else
  813.               fprintf_filtered (stream, ", ");
  814.             wrap_here (n_spaces (2 + 2 * recurse));
  815.           
  816.           rep1 = i + 1;
  817.           reps = 1;
  818.           while (rep1 < len
  819.              && !bcmp (valaddr + i * eltlen,
  820.                    valaddr + rep1 * eltlen, eltlen))
  821.             {
  822.               ++reps;
  823.               ++rep1;
  824.             }
  825.  
  826.           if (reps > REPEAT_COUNT_THRESHOLD)
  827.             {
  828.               val_print (elttype, valaddr + i * eltlen,
  829.                  0, stream, format, deref_ref,
  830.                  recurse + 1, pretty);
  831.               fprintf_filtered (stream, " <repeats %u times>", reps);
  832.               i = rep1 - 1;
  833.               things_printed += REPEAT_COUNT_THRESHOLD;
  834.             }
  835.           else
  836.             {
  837.               val_print (elttype, valaddr + i * eltlen,
  838.                  0, stream, format, deref_ref,
  839.                  recurse + 1, pretty);
  840.               things_printed++;
  841.             }
  842.         }
  843.           if (i < len)
  844.         fprintf_filtered (stream, "...");
  845.         }
  846.       fprintf_filtered (stream, "}");
  847.       break;
  848.     }
  849.       /* Array of unspecified length: treat like pointer to first elt.  */
  850.       valaddr = (char *) &address;
  851.  
  852.     case TYPE_CODE_PTR:
  853.       if (format && format != 's')
  854.     {
  855.       print_scalar_formatted (valaddr, type, format, 0, stream);
  856.       break;
  857.     }
  858.       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
  859.     {
  860.       struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
  861.       struct fn_field *f;
  862.       int j, len2;
  863.       char *kind = "";
  864.       CORE_ADDR addr;
  865.  
  866.       addr = unpack_pointer (lookup_pointer_type (builtin_type_void),
  867.                 valaddr);
  868.       if (addr < 128)            /* FIXME!  What is this 128? */
  869.         {
  870.           len = TYPE_NFN_FIELDS (domain);
  871.           for (i = 0; i < len; i++)
  872.         {
  873.           f = TYPE_FN_FIELDLIST1 (domain, i);
  874.           len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
  875.  
  876.           for (j = 0; j < len2; j++)
  877.             {
  878.               QUIT;
  879.               if (TYPE_FN_FIELD_VOFFSET (f, j) == addr)
  880.             {
  881.               kind = "virtual";
  882.               goto common;
  883.             }
  884.             }
  885.         }
  886.         }
  887.       else
  888.         {
  889.           struct symbol *sym = find_pc_function (addr);
  890.           if (sym == 0)
  891.         error ("invalid pointer to member function");
  892.           len = TYPE_NFN_FIELDS (domain);
  893.           for (i = 0; i < len; i++)
  894.         {
  895.           f = TYPE_FN_FIELDLIST1 (domain, i);
  896.           len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
  897.  
  898.           for (j = 0; j < len2; j++)
  899.             {
  900.               QUIT;
  901.               if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
  902.             goto common;
  903.             }
  904.         }
  905.         }
  906.     common:
  907.       if (i < len)
  908.         {
  909.           fprintf_filtered (stream, "&");
  910.           type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
  911.           fprintf (stream, kind);
  912.           if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
  913.           && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
  914.         type_print_method_args
  915.           (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
  916.            TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
  917.           else
  918.         type_print_method_args
  919.           (TYPE_FN_FIELD_ARGS (f, j), "",
  920.            TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
  921.           break;
  922.         }
  923.       fprintf_filtered (stream, "(");
  924.         type_print (type, "", stream, -1);
  925.       fprintf_filtered (stream, ") %d", (int) addr >> 3);
  926.     }
  927.       else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
  928.     {
  929.       print_class_member (valaddr,
  930.                   TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
  931.                   stream, "&");
  932.     }
  933.       else
  934.     {
  935.       CORE_ADDR addr = unpack_pointer (type, valaddr);
  936.       elttype = TYPE_TARGET_TYPE (type);
  937.  
  938.       if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
  939.         {
  940.           /* Try to print what function it points to.  */
  941.           print_address_demangle (addr, stream, demangle);
  942.           /* Return value is irrelevant except for string pointers.  */
  943.           return 0;
  944.         }
  945.  
  946.       if (addressprint && format != 's')
  947.         fprintf_filtered (stream, "0x%x", addr);
  948.  
  949.       /* For a pointer to char or unsigned char,
  950.          also print the string pointed to, unless pointer is null.  */
  951.       i = 0;        /* Number of characters printed.  */
  952.       if (TYPE_LENGTH (elttype) == 1 
  953.           && TYPE_CODE (elttype) == TYPE_CODE_INT
  954.           && (format == 0 || format == 's')
  955.           && addr != 0
  956.           /* If print_max is UINT_MAX, the alloca below will fail.
  957.              In that case don't try to print the string.  */
  958.           && print_max < UINT_MAX)
  959.         {
  960.           int first_addr_err = 0;
  961.           int errcode = 0;
  962.           
  963.           /* Get first character.  */
  964.           errcode = target_read_memory (addr, (char *)&c, 1);
  965.           if (errcode != 0)
  966.         {
  967.           /* First address out of bounds.  */
  968.           first_addr_err = 1;
  969.         }
  970.           else
  971.         {
  972.           /* A real string.  */
  973.           char *string = (char *) alloca (print_max);
  974.  
  975.           /* If the loop ends by us hitting print_max characters,
  976.              we need to have elipses at the end.  */
  977.           int force_ellipses = 1;
  978.  
  979.           /* This loop always fetches print_max characters, even
  980.              though print_string might want to print more or fewer
  981.              (with repeated characters).  This is so that
  982.              we don't spend forever fetching if we print
  983.              a long string consisting of the same character
  984.              repeated.  Also so we can do it all in one memory
  985.              operation, which is faster.  However, this will be
  986.              slower if print_max is set high, e.g. if you set
  987.              print_max to 1000, not only will it take a long
  988.              time to fetch short strings, but if you are near
  989.              the end of the address space, it might not work. */
  990.           QUIT;
  991.           errcode = target_read_memory (addr, string, print_max);
  992.           if (errcode != 0)
  993.             {
  994.               /* Try reading just one character.  If that succeeds,
  995.              assume we hit the end of the address space, but
  996.              the initial part of the string is probably safe. */
  997.               char x[1];
  998.               errcode = target_read_memory (addr, x, 1);
  999.             }
  1000.           if (errcode != 0)
  1001.               force_ellipses = 0;
  1002.           else 
  1003.             for (i = 0; i < print_max; i++)
  1004.               if (string[i] == '\0')
  1005.             {
  1006.               force_ellipses = 0;
  1007.               break;
  1008.                 }
  1009.           QUIT;
  1010.  
  1011.           if (addressprint)
  1012.             fputs_filtered (" ", stream);
  1013.           print_string (stream, string, i, force_ellipses);
  1014.         }
  1015.  
  1016.           if (errcode != 0)
  1017.         {
  1018.           if (errcode == EIO)
  1019.             {
  1020.               fprintf_filtered (stream,
  1021.                     (" <Address 0x%x out of bounds>"
  1022.                      + first_addr_err),
  1023.                     addr + i);
  1024.             }
  1025.           else
  1026.             {
  1027.               if (errcode >= sys_nerr || errcode < 0)
  1028.             error ("Error reading memory address 0x%x: unknown error (%d).",
  1029.                    addr + i, errcode);
  1030.               else
  1031.             error ("Error reading memory address 0x%x: %s.",
  1032.                    addr + i, sys_errlist[errcode]);
  1033.             }
  1034.         }
  1035.  
  1036.           fflush (stream);
  1037.         }
  1038.       else /* print vtbl's nicely */
  1039.        if (is_vtbl_member(type))
  1040.           {
  1041.           CORE_ADDR vt_address = unpack_pointer (type, valaddr);
  1042.  
  1043.           struct minimal_symbol *msymbol =
  1044.         lookup_minimal_symbol_by_pc (vt_address);
  1045.           if ((msymbol != NULL) && (vt_address == msymbol -> address))
  1046.         {
  1047.           fputs_filtered (" <", stream);
  1048.           fputs_demangled (msymbol -> name, stream, 1);
  1049.           fputs_filtered (">", stream);
  1050.         }
  1051.           if (vtblprint)
  1052.             {
  1053.           value vt_val;
  1054.  
  1055.           vt_val = value_at (TYPE_TARGET_TYPE (type), vt_address);
  1056.           val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val),
  1057.                  VALUE_ADDRESS (vt_val), stream, format,
  1058.                  deref_ref, recurse + 1, pretty);
  1059.           if (pretty)
  1060.             {
  1061.               fprintf_filtered (stream, "\n");
  1062.               print_spaces_filtered (2 + 2 * recurse, stream);
  1063.             }
  1064.             }
  1065.           }
  1066.  
  1067.       /* Return number of characters printed, plus one for the
  1068.          terminating null if we have "reached the end".  */
  1069.       return i + (print_max && i != print_max);
  1070.     }
  1071.       break;
  1072.  
  1073.     case TYPE_CODE_MEMBER:
  1074.       error ("not implemented: member type in val_print");
  1075.       break;
  1076.  
  1077.     case TYPE_CODE_REF:
  1078.       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
  1079.         {
  1080.       print_class_member (valaddr,
  1081.                   TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
  1082.                   stream, "");
  1083.       break;
  1084.     }
  1085.       if (addressprint)
  1086.         {
  1087.       fprintf_filtered (stream, "@0x%lx",
  1088.                   unpack_long (builtin_type_int, valaddr));
  1089.       if (deref_ref)
  1090.         fputs_filtered (": ", stream);
  1091.         }
  1092.       /* De-reference the reference.  */
  1093.       if (deref_ref)
  1094.     {
  1095.       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
  1096.         {
  1097.           value deref_val =
  1098.         value_at
  1099.           (TYPE_TARGET_TYPE (type),
  1100.            unpack_pointer (lookup_pointer_type (builtin_type_void),
  1101.                    valaddr));
  1102.           val_print (VALUE_TYPE (deref_val), VALUE_CONTENTS (deref_val),
  1103.              VALUE_ADDRESS (deref_val), stream, format,
  1104.              deref_ref, recurse + 1, pretty);
  1105.         }
  1106.       else
  1107.         fputs_filtered ("???", stream);
  1108.     }
  1109.       break;
  1110.  
  1111.     case TYPE_CODE_UNION:
  1112.       if (recurse && !unionprint)
  1113.     {
  1114.       fprintf_filtered (stream, "{...}");
  1115.       break;
  1116.     }
  1117.       /* Fall through.  */
  1118.     case TYPE_CODE_STRUCT:
  1119.       if (vtblprint && is_vtbl_ptr_type(type))
  1120.     {
  1121.           /* Print the unmangled name if desired.  */
  1122.       print_address_demangle(*((int *) (valaddr +    /* FIXME bytesex */
  1123.           TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8)),
  1124.           stream, demangle);
  1125.       break;
  1126.     }
  1127.       val_print_fields (type, valaddr, stream, format, recurse, pretty, 0);
  1128.       break;
  1129.  
  1130.     case TYPE_CODE_ENUM:
  1131.       if (format)
  1132.     {
  1133.       print_scalar_formatted (valaddr, type, format, 0, stream);
  1134.       break;
  1135.     }
  1136.       len = TYPE_NFIELDS (type);
  1137.       val = unpack_long (builtin_type_int, valaddr);
  1138.       for (i = 0; i < len; i++)
  1139.     {
  1140.       QUIT;
  1141.       if (val == TYPE_FIELD_BITPOS (type, i))
  1142.         break;
  1143.     }
  1144.       if (i < len)
  1145.     fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  1146.       else
  1147. #ifdef LONG_LONG
  1148.     fprintf_filtered (stream, "%lld", val);
  1149. #else
  1150.     fprintf_filtered (stream, "%ld", val);
  1151. #endif
  1152.       break;
  1153.  
  1154.     case TYPE_CODE_FUNC:
  1155.       if (format)
  1156.     {
  1157.       print_scalar_formatted (valaddr, type, format, 0, stream);
  1158.       break;
  1159.     }
  1160.       /* FIXME, we should consider, at least for ANSI C language, eliminating
  1161.      the distinction made between FUNCs and POINTERs to FUNCs.  */
  1162.       fprintf_filtered (stream, "{");
  1163.       type_print (type, "", stream, -1);
  1164.       fprintf_filtered (stream, "} ");
  1165.       /* Try to print what function it points to, and its address.  */
  1166.       print_address_demangle (address, stream, demangle);
  1167.       break;
  1168.  
  1169.     case TYPE_CODE_INT:
  1170.       if (format || output_format)
  1171.     {
  1172.       print_scalar_formatted (valaddr, type,
  1173.                   format? format: output_format,
  1174.                   0, stream);
  1175.       break;
  1176.     }
  1177.       if (TYPE_LENGTH (type) > sizeof (LONGEST))
  1178.     {
  1179.       if (TYPE_UNSIGNED (type))
  1180.         {
  1181.           /* First figure out whether the number in fact has zeros
  1182.          in all its bytes more significant than least significant
  1183.          sizeof (LONGEST) ones.  */
  1184.           char *p;
  1185.           /* Pointer to first (i.e. lowest address) nonzero character.  */
  1186.           char *first_addr;
  1187.           len = TYPE_LENGTH (type);
  1188.  
  1189. #if TARGET_BYTE_ORDER == BIG_ENDIAN
  1190.           for (p = valaddr;
  1191.            len > sizeof (LONGEST)
  1192.            && p < valaddr + TYPE_LENGTH (type);
  1193.            p++)
  1194. #else /* Little endian.  */
  1195.           first_addr = valaddr;
  1196.           for (p = valaddr + TYPE_LENGTH (type);
  1197.            len > sizeof (LONGEST) && p >= valaddr;
  1198.            p--)
  1199. #endif /* Little endian.  */
  1200.         {
  1201.           if (*p == 0)
  1202.             len--;
  1203.           else
  1204.             break;
  1205.         }
  1206. #if TARGET_BYTE_ORDER == BIG_ENDIAN
  1207.           first_addr = p;
  1208. #endif
  1209.           
  1210.           if (len <= sizeof (LONGEST))
  1211.         {
  1212.           /* We can print it in decimal.  */
  1213.           fprintf_filtered
  1214.             (stream, 
  1215. #if defined (LONG_LONG)
  1216.              "%llu",
  1217. #else
  1218.              "%lu",
  1219. #endif
  1220.              unpack_long (BUILTIN_TYPE_LONGEST, first_addr));
  1221.         }
  1222.           else
  1223.         {
  1224.           /* It is big, so print it in hex.  */
  1225.           print_hex_chars (stream, (unsigned char *)first_addr, len);
  1226.         }
  1227.         }
  1228.       else
  1229.         {
  1230.           /* Signed.  One could assume two's complement (a reasonable
  1231.          assumption, I think) and do better than this.  */
  1232.           print_hex_chars (stream, (unsigned char *)valaddr,
  1233.                    TYPE_LENGTH (type));
  1234.         }
  1235.       break;
  1236.     }
  1237. #ifdef PRINT_TYPELESS_INTEGER
  1238.       PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr));
  1239. #else
  1240. #ifndef LONG_LONG
  1241.       fprintf_filtered (stream,
  1242.             TYPE_UNSIGNED (type) ? "%u" : "%d",
  1243.             unpack_long (type, valaddr));
  1244. #else
  1245.       fprintf_filtered (stream,
  1246.             TYPE_UNSIGNED (type) ? "%llu" : "%lld",
  1247.             unpack_long (type, valaddr));
  1248. #endif
  1249. #endif
  1250.             
  1251.       if (TYPE_LENGTH (type) == 1)
  1252.     {
  1253.       fprintf_filtered (stream, " '");
  1254.       printchar ((unsigned char) unpack_long (type, valaddr), 
  1255.              stream, '\'');
  1256.       fprintf_filtered (stream, "'");
  1257.     }
  1258.       break;
  1259.  
  1260.     case TYPE_CODE_FLT:
  1261.       if (format)
  1262.     print_scalar_formatted (valaddr, type, format, 0, stream);
  1263.       else
  1264.     print_floating (valaddr, type, stream);
  1265.       break;
  1266.  
  1267.     case TYPE_CODE_VOID:
  1268.       fprintf_filtered (stream, "void");
  1269.       break;
  1270.  
  1271.     case TYPE_CODE_UNDEF:
  1272.       /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
  1273.      dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
  1274.      and no complete type for struct foo in that file.  */
  1275.       fprintf_filtered (stream, "<unknown struct>");
  1276.       break;
  1277.  
  1278.     case TYPE_CODE_ERROR:
  1279.       fprintf_filtered (stream, "?");
  1280.       break;
  1281.  
  1282.     case TYPE_CODE_RANGE:
  1283.       /* FIXME, we should not ever have to print one of these yet.  */
  1284.       fprintf_filtered (stream, "<range type>");
  1285.       break;
  1286.  
  1287.     default:
  1288.       error ("Invalid type code in symbol table.");
  1289.     }
  1290.   fflush (stream);
  1291.   return 0;
  1292. }
  1293.  
  1294. /* Print a description of a type in the format of a 
  1295.    typedef for the current language.
  1296.    NEW is the new name for a type TYPE. */
  1297. void
  1298. typedef_print (type, new, stream)
  1299.    struct type *type;
  1300.    struct symbol *new;
  1301.    FILE *stream;
  1302. {
  1303.    switch (current_language->la_language)
  1304.    {
  1305. #ifdef _LANG_c
  1306.    case language_c:
  1307.    case language_cplus:
  1308.       fprintf_filtered(stream, "typedef ");
  1309.       type_print(type,"",stream,0);
  1310.       if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
  1311.      || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (new))),
  1312.              SYMBOL_NAME (new)))
  1313.      fprintf_filtered(stream,  " %s", SYMBOL_NAME(new));
  1314.       break;
  1315. #endif
  1316. #ifdef _LANG_m2
  1317.    case language_m2:
  1318.       fprintf_filtered(stream, "TYPE ");
  1319.       if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
  1320.      strcmp (TYPE_NAME(SYMBOL_TYPE(new)),
  1321.             SYMBOL_NAME(new)))
  1322.      fprintf_filtered(stream, "%s = ", SYMBOL_NAME(new));
  1323.       else
  1324.      fprintf_filtered(stream, "<builtin> = ");
  1325.       type_print(type,"",stream,0);
  1326.       break;
  1327. #endif
  1328.    default:
  1329.       error("Language not supported.");
  1330.    }
  1331.    fprintf_filtered(stream, ";\n");
  1332. }
  1333.  
  1334.  
  1335. /* Print a description of a type TYPE
  1336.    in the form of a declaration of a variable named VARSTRING.
  1337.    (VARSTRING is demangled if necessary.)
  1338.    Output goes to STREAM (via stdio).
  1339.    If SHOW is positive, we show the contents of the outermost level
  1340.    of structure even if there is a type name that could be used instead.
  1341.    If SHOW is negative, we never show the details of elements' types.  */
  1342.  
  1343. void
  1344. type_print (type, varstring, stream, show)
  1345.      struct type *type;
  1346.      char *varstring;
  1347.      FILE *stream;
  1348.      int show;
  1349. {
  1350.   type_print_1 (type, varstring, stream, show, 0);
  1351. }
  1352.  
  1353. /* LEVEL is the depth to indent lines by.  */
  1354.  
  1355. void
  1356. type_print_1 (type, varstring, stream, show, level)
  1357.      struct type *type;
  1358.      char *varstring;
  1359.      FILE *stream;
  1360.      int show;
  1361.      int level;
  1362. {
  1363.   register enum type_code code;
  1364.   type_print_base (type, stream, show, level);
  1365.   code = TYPE_CODE (type);
  1366.   if ((varstring && *varstring)
  1367.       ||
  1368.       /* Need a space if going to print stars or brackets;
  1369.      but not if we will print just a type name.  */
  1370.       ((show > 0 || TYPE_NAME (type) == 0)
  1371.        &&
  1372.        (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
  1373.     || code == TYPE_CODE_METHOD
  1374.     || code == TYPE_CODE_ARRAY
  1375.     || code == TYPE_CODE_MEMBER
  1376.     || code == TYPE_CODE_REF)))
  1377.     fprintf_filtered (stream, " ");
  1378.   type_print_varspec_prefix (type, stream, show, 0);
  1379.   fputs_demangled (varstring, stream, -1);    /* Print demangled name
  1380.                            without arguments */
  1381.   type_print_varspec_suffix (type, stream, show, 0);
  1382. }
  1383.  
  1384. /* Print the method arguments ARGS to the file STREAM.  */
  1385. static void
  1386. type_print_method_args (args, prefix, varstring, staticp, stream)
  1387.      struct type **args;
  1388.      char *prefix, *varstring;
  1389.      int staticp;
  1390.      FILE *stream;
  1391. {
  1392.   int i;
  1393.  
  1394.   fputs_demangled (prefix, stream, 1);
  1395.   fputs_demangled (varstring, stream, 1);
  1396.   fputs_filtered (" (", stream);
  1397.   if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
  1398.     {
  1399.       i = !staticp;        /* skip the class variable */
  1400.       while (1)
  1401.     {
  1402.       type_print (args[i++], "", stream, 0);
  1403.       if (!args[i]) 
  1404.         {
  1405.           fprintf_filtered (stream, " ...");
  1406.           break;
  1407.         }
  1408.       else if (args[i]->code != TYPE_CODE_VOID)
  1409.         {
  1410.           fprintf_filtered (stream, ", ");
  1411.         }
  1412.       else break;
  1413.     }
  1414.     }
  1415.   fprintf_filtered (stream, ")");
  1416. }
  1417.   
  1418. /* If TYPE is a derived type, then print out derivation
  1419.    information.  Print out all layers of the type heirarchy
  1420.    until we encounter one with multiple inheritance.
  1421.    At that point, print out that ply, and return.  */
  1422. static void
  1423. type_print_derivation_info (stream, type)
  1424.      FILE *stream;
  1425.      struct type *type;
  1426. {
  1427.   char *name;
  1428.   int i, n_baseclasses = TYPE_N_BASECLASSES (type);
  1429.   struct type *basetype = 0;
  1430.  
  1431.   while (type && n_baseclasses > 0)
  1432.     {
  1433.       /* Not actually sure about this one -- Bryan. */
  1434.       check_stub_type (type);
  1435.       
  1436.       fprintf_filtered (stream, ": ");
  1437.       for (i = 0; ;)
  1438.     {
  1439.       basetype = TYPE_BASECLASS (type, i);
  1440.       if (name = type_name_no_tag (basetype))
  1441.         {
  1442.           fprintf_filtered (stream, "%s%s ",
  1443.                BASETYPE_VIA_PUBLIC(type, i) ? "public" : "private",
  1444.                BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : "");
  1445.           fputs_filtered (name, stream);
  1446.         }
  1447.       i++;
  1448.       if (i >= n_baseclasses)
  1449.           break;
  1450.       fprintf_filtered (stream, ", ");
  1451.     }
  1452.  
  1453.       fprintf_filtered (stream, " ");
  1454.       if (n_baseclasses != 1)
  1455.     break;
  1456.       n_baseclasses = TYPE_N_BASECLASSES (basetype);
  1457.       type = basetype;
  1458.     }
  1459. }
  1460.  
  1461. /* Print any asterisks or open-parentheses needed before the
  1462.    variable name (to describe its type).
  1463.  
  1464.    On outermost call, pass 0 for PASSED_A_PTR.
  1465.    On outermost call, SHOW > 0 means should ignore
  1466.    any typename for TYPE and show its details.
  1467.    SHOW is always zero on recursive calls.  */
  1468.  
  1469. static void
  1470. type_print_varspec_prefix (type, stream, show, passed_a_ptr)
  1471.      struct type *type;
  1472.      FILE *stream;
  1473.      int show;
  1474.      int passed_a_ptr;
  1475. {
  1476.   char *name;
  1477.   if (type == 0)
  1478.     return;
  1479.  
  1480.   if (TYPE_NAME (type) && show <= 0)
  1481.     return;
  1482.  
  1483.   QUIT;
  1484.  
  1485.   switch (TYPE_CODE (type))
  1486.     {
  1487.     case TYPE_CODE_PTR:
  1488.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
  1489.       fprintf_filtered (stream, "*");
  1490.       break;
  1491.  
  1492.     case TYPE_CODE_MEMBER:
  1493.       if (passed_a_ptr)
  1494.     fprintf_filtered (stream, "(");
  1495.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  1496.                  0);
  1497.       fprintf_filtered (stream, " ");
  1498.       name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
  1499.       if (name)
  1500.     fputs_filtered (name, stream);
  1501.       else
  1502.         type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
  1503.       fprintf_filtered (stream, "::");
  1504.       break;
  1505.  
  1506.     case TYPE_CODE_METHOD:
  1507.       if (passed_a_ptr)
  1508.     fprintf (stream, "(");
  1509.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  1510.                  0);
  1511.       if (passed_a_ptr)
  1512.     {
  1513.       fprintf_filtered (stream, " ");
  1514.       type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
  1515.                passed_a_ptr);
  1516.       fprintf_filtered (stream, "::");
  1517.     }
  1518.       break;
  1519.  
  1520.     case TYPE_CODE_REF:
  1521.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
  1522.       fprintf_filtered (stream, "&");
  1523.       break;
  1524.  
  1525.     case TYPE_CODE_FUNC:
  1526.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  1527.                  0);
  1528.       if (passed_a_ptr)
  1529.     fprintf_filtered (stream, "(");
  1530.       break;
  1531.  
  1532.     case TYPE_CODE_ARRAY:
  1533.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  1534.                  0);
  1535.       if (passed_a_ptr)
  1536.     fprintf_filtered (stream, "(");
  1537.       break;
  1538.  
  1539.     case TYPE_CODE_UNDEF:
  1540.     case TYPE_CODE_STRUCT:
  1541.     case TYPE_CODE_UNION:
  1542.     case TYPE_CODE_ENUM:
  1543.     case TYPE_CODE_INT:
  1544.     case TYPE_CODE_FLT:
  1545.     case TYPE_CODE_VOID:
  1546.     case TYPE_CODE_ERROR:
  1547.     case TYPE_CODE_CHAR:
  1548.     case TYPE_CODE_BOOL:
  1549.       /* These types need no prefix.  They are listed here so that
  1550.      gcc -Wall will reveal any types that haven't been handled.  */
  1551.       break;
  1552.     }
  1553. }
  1554.  
  1555. /* Print any array sizes, function arguments or close parentheses
  1556.    needed after the variable name (to describe its type).
  1557.    Args work like type_print_varspec_prefix.  */
  1558.  
  1559. static void
  1560. type_print_varspec_suffix (type, stream, show, passed_a_ptr)
  1561.      struct type *type;
  1562.      FILE *stream;
  1563.      int show;
  1564.      int passed_a_ptr;
  1565. {
  1566.   if (type == 0)
  1567.     return;
  1568.  
  1569.   if (TYPE_NAME (type) && show <= 0)
  1570.     return;
  1571.  
  1572.   QUIT;
  1573.  
  1574.   switch (TYPE_CODE (type))
  1575.     {
  1576.     case TYPE_CODE_ARRAY:
  1577.       if (passed_a_ptr)
  1578.     fprintf_filtered (stream, ")");
  1579.       
  1580.       fprintf_filtered (stream, "[");
  1581.       if (TYPE_LENGTH (type) > 0
  1582.       && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
  1583.     fprintf_filtered (stream, "%d",
  1584.               (TYPE_LENGTH (type)
  1585.                / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
  1586.       fprintf_filtered (stream, "]");
  1587.       
  1588.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
  1589.                  0);
  1590.       break;
  1591.  
  1592.     case TYPE_CODE_MEMBER:
  1593.       if (passed_a_ptr)
  1594.     fprintf_filtered (stream, ")");
  1595.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0);
  1596.       break;
  1597.  
  1598.     case TYPE_CODE_METHOD:
  1599.       if (passed_a_ptr)
  1600.     fprintf_filtered (stream, ")");
  1601.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0);
  1602.       if (passed_a_ptr)
  1603.     {
  1604.       int i;
  1605.       struct type **args = TYPE_ARG_TYPES (type);
  1606.  
  1607.       fprintf_filtered (stream, "(");
  1608.       if (args[1] == 0)
  1609.         fprintf_filtered (stream, "...");
  1610.       else for (i = 1; args[i] != 0 && args[i]->code != TYPE_CODE_VOID; i++)
  1611.         {
  1612.           type_print_1 (args[i], "", stream, -1, 0);
  1613.           if (args[i+1] == 0)
  1614.         fprintf_filtered (stream, "...");
  1615.           else if (args[i+1]->code != TYPE_CODE_VOID) {
  1616.         fprintf_filtered (stream, ",");
  1617.         wrap_here ("    ");
  1618.           }
  1619.         }
  1620.       fprintf_filtered (stream, ")");
  1621.     }
  1622.       break;
  1623.  
  1624.     case TYPE_CODE_PTR:
  1625.     case TYPE_CODE_REF:
  1626.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1);
  1627.       break;
  1628.  
  1629.     case TYPE_CODE_FUNC:
  1630.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
  1631.                  passed_a_ptr);
  1632.       if (passed_a_ptr)
  1633.     fprintf_filtered (stream, ")");
  1634.       fprintf_filtered (stream, "()");
  1635.       break;
  1636.  
  1637.     case TYPE_CODE_UNDEF:
  1638.     case TYPE_CODE_STRUCT:
  1639.     case TYPE_CODE_UNION:
  1640.     case TYPE_CODE_ENUM:
  1641.     case TYPE_CODE_INT:
  1642.     case TYPE_CODE_FLT:
  1643.     case TYPE_CODE_VOID:
  1644.     case TYPE_CODE_ERROR:
  1645.     case TYPE_CODE_CHAR:
  1646.     case TYPE_CODE_BOOL:
  1647.       /* These types do not need a suffix.  They are listed so that
  1648.      gcc -Wall will report types that may not have been considered.  */
  1649.       break;
  1650.     }
  1651. }
  1652.  
  1653. /* Print the name of the type (or the ultimate pointer target,
  1654.    function value or array element), or the description of a
  1655.    structure or union.
  1656.  
  1657.    SHOW nonzero means don't print this type as just its name;
  1658.    show its real definition even if it has a name.
  1659.    SHOW zero means print just typename or struct tag if there is one
  1660.    SHOW negative means abbreviate structure elements.
  1661.    SHOW is decremented for printing of structure elements.
  1662.  
  1663.    LEVEL is the depth to indent by.
  1664.    We increase it for some recursive calls.  */
  1665.  
  1666. static void
  1667. type_print_base (type, stream, show, level)
  1668.      struct type *type;
  1669.      FILE *stream;
  1670.      int show;
  1671.      int level;
  1672. {
  1673.   char *name;
  1674.   register int i;
  1675.   register int len;
  1676.   register int lastval;
  1677.  
  1678.   QUIT;
  1679.  
  1680.   wrap_here ("    ");
  1681.   if (type == 0)
  1682.     {
  1683.       fprintf_filtered (stream, "<type unknown>");
  1684.       return;
  1685.     }
  1686.  
  1687.   if (TYPE_NAME (type) && show <= 0)
  1688.     {
  1689.       fputs_filtered (TYPE_NAME (type), stream);
  1690.       return;
  1691.     }
  1692.  
  1693.   switch (TYPE_CODE (type))
  1694.     {
  1695.     case TYPE_CODE_ARRAY:
  1696.     case TYPE_CODE_PTR:
  1697.     case TYPE_CODE_MEMBER:
  1698.     case TYPE_CODE_REF:
  1699.     case TYPE_CODE_FUNC:
  1700.     case TYPE_CODE_METHOD:
  1701.       type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
  1702.       break;
  1703.  
  1704.     case TYPE_CODE_STRUCT:
  1705.       fprintf_filtered (stream, "struct ");
  1706.       goto struct_union;
  1707.  
  1708.     case TYPE_CODE_UNION:
  1709.       fprintf_filtered (stream, "union ");
  1710.     struct_union:
  1711.       if (name = type_name_no_tag (type))
  1712.     {
  1713.       fputs_filtered (name, stream);
  1714.       fputs_filtered (" ", stream);
  1715.       wrap_here ("    ");
  1716.     }
  1717.       if (show < 0)
  1718.     fprintf_filtered (stream, "{...}");
  1719.       else
  1720.     {
  1721.       check_stub_type (type);
  1722.       
  1723.       type_print_derivation_info (stream, type);
  1724.       
  1725.       fprintf_filtered (stream, "{");
  1726.       len = TYPE_NFIELDS (type);
  1727.       if (len)
  1728.         fprintf_filtered (stream, "\n");
  1729.       else
  1730.         {
  1731.           if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
  1732.         fprintf_filtered (stream, "<incomplete type>\n");
  1733.           else
  1734.         fprintf_filtered (stream, "<no data fields>\n");
  1735.         }
  1736.  
  1737.       /* If there is a base class for this type,
  1738.          do not print the field that it occupies.  */
  1739.       for (i = TYPE_N_BASECLASSES (type); i < len; i++)
  1740.         {
  1741.           QUIT;
  1742.           /* Don't print out virtual function table.  */
  1743.           if ((TYPE_FIELD_NAME (type, i))[5] == CPLUS_MARKER &&
  1744.           !strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5))
  1745.         continue;
  1746.  
  1747.           print_spaces_filtered (level + 4, stream);
  1748.           if (TYPE_FIELD_STATIC (type, i))
  1749.         {
  1750.           fprintf_filtered (stream, "static ");
  1751.         }
  1752.           type_print_1 (TYPE_FIELD_TYPE (type, i),
  1753.                 TYPE_FIELD_NAME (type, i),
  1754.                 stream, show - 1, level + 4);
  1755.           if (!TYPE_FIELD_STATIC (type, i)
  1756.           && TYPE_FIELD_PACKED (type, i))
  1757.         {
  1758.           /* It is a bitfield.  This code does not attempt
  1759.              to look at the bitpos and reconstruct filler,
  1760.              unnamed fields.  This would lead to misleading
  1761.              results if the compiler does not put out fields
  1762.              for such things (I don't know what it does).  */
  1763.           fprintf_filtered (stream, " : %d",
  1764.                     TYPE_FIELD_BITSIZE (type, i));
  1765.         }
  1766.           fprintf_filtered (stream, ";\n");
  1767.         }
  1768.  
  1769.       /* C++: print out the methods */
  1770.       len = TYPE_NFN_FIELDS (type);
  1771.       if (len) fprintf_filtered (stream, "\n");
  1772.       for (i = 0; i < len; i++)
  1773.         {
  1774.           struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
  1775.           int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
  1776.           char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
  1777.           int is_constructor = name && strcmp(method_name, name) == 0;
  1778.           for (j = 0; j < len2; j++)
  1779.         {
  1780.           QUIT;
  1781.           print_spaces_filtered (level + 4, stream);
  1782.           if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  1783.             fprintf_filtered (stream, "virtual ");
  1784.           else if (TYPE_FN_FIELD_STATIC_P (f, j))
  1785.             fprintf_filtered (stream, "static ");
  1786.           if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
  1787.             {
  1788.               /* Keep GDB from crashing here.  */
  1789.               fprintf (stream, "<undefined type> %s;\n",
  1790.                    TYPE_FN_FIELD_PHYSNAME (f, j));
  1791.               break;
  1792.             }
  1793.           else if (!is_constructor)
  1794.             {
  1795.               type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
  1796.                   "", stream, 0);
  1797.               fputs_filtered (" ", stream);
  1798.             }
  1799.           if (TYPE_FN_FIELD_STUB (f, j))
  1800.             {
  1801.               /* Build something we can demangle.  */
  1802.               char *mangled_name = gdb_mangle_name (type, i, j);
  1803.               char *demangled_name = cplus_demangle (mangled_name, 1);
  1804.               if (demangled_name == 0)
  1805.             fprintf_filtered (stream, "<badly mangled name %s>",
  1806.                 mangled_name);
  1807.               else 
  1808.             {
  1809.               fprintf_filtered (stream, "%s",
  1810.                   strchr (demangled_name, ':') + 2);
  1811.               free (demangled_name);
  1812.             }
  1813.               free (mangled_name);
  1814.             }
  1815.           else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
  1816.                 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
  1817.             type_print_method_args
  1818.               (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
  1819.                method_name, 0, stream);
  1820.           else
  1821.             type_print_method_args
  1822.               (TYPE_FN_FIELD_ARGS (f, j), "",
  1823.                method_name,
  1824.                TYPE_FN_FIELD_STATIC_P (f, j), stream);
  1825.  
  1826.           fprintf_filtered (stream, ";\n");
  1827.         }
  1828.         }
  1829.  
  1830.       print_spaces_filtered (level, stream);
  1831.       fprintf_filtered (stream, "}");
  1832.     }
  1833.       break;
  1834.  
  1835.     case TYPE_CODE_ENUM:
  1836.       fprintf_filtered (stream, "enum ");
  1837.       if (name = type_name_no_tag (type))
  1838.     {
  1839.       fputs_filtered (name, stream);
  1840.       fputs_filtered (" ", stream);
  1841.     }
  1842.       wrap_here ("    ");
  1843.       if (show < 0)
  1844.     fprintf_filtered (stream, "{...}");
  1845.       else
  1846.     {
  1847.       fprintf_filtered (stream, "{");
  1848.       len = TYPE_NFIELDS (type);
  1849.       lastval = 0;
  1850.       for (i = 0; i < len; i++)
  1851.         {
  1852.           QUIT;
  1853.           if (i) fprintf_filtered (stream, ", ");
  1854.           wrap_here ("    ");
  1855.           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  1856.           if (lastval != TYPE_FIELD_BITPOS (type, i))
  1857.         {
  1858.           fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
  1859.           lastval = TYPE_FIELD_BITPOS (type, i);
  1860.         }
  1861.           lastval++;
  1862.         }
  1863.       fprintf_filtered (stream, "}");
  1864.     }
  1865.       break;
  1866.  
  1867.     case TYPE_CODE_INT:
  1868.       name = 0;
  1869.       if (TYPE_LENGTH (type) <= sizeof (LONGEST))
  1870.     {
  1871.       if (TYPE_UNSIGNED (type))
  1872.         name = unsigned_type_table[TYPE_LENGTH (type)];
  1873.       else
  1874.         name = signed_type_table[TYPE_LENGTH (type)];
  1875.     }
  1876.       if (name)
  1877.     fputs_filtered (name, stream);
  1878.       else
  1879.     fprintf_filtered (stream, "<%d bit integer>",
  1880.               TYPE_LENGTH (type) * TARGET_CHAR_BIT);
  1881.       break;
  1882.  
  1883.     case TYPE_CODE_FLT:
  1884.       name = float_type_table[TYPE_LENGTH (type)];
  1885.       fputs_filtered (name, stream);
  1886.       break;
  1887.  
  1888.     case TYPE_CODE_VOID:
  1889.       fprintf_filtered (stream, "void");
  1890.       break;
  1891.  
  1892.     case TYPE_CODE_UNDEF:
  1893.       fprintf_filtered (stream, "struct <unknown>");
  1894.       break;
  1895.  
  1896.     case TYPE_CODE_ERROR:
  1897.       fprintf_filtered (stream, "<unknown type>");
  1898.       break;
  1899.  
  1900.     case TYPE_CODE_RANGE:
  1901.       /* This should not occur */
  1902.       fprintf_filtered (stream, "<range type>");
  1903.       break;
  1904.  
  1905.     default:
  1906.       error ("Invalid type code in symbol table.");
  1907.     }
  1908. }
  1909.  
  1910. #if 0
  1911. /* Validate an input or output radix setting, and make sure the user
  1912.    knows what they really did here.  Radix setting is confusing, e.g.
  1913.    setting the input radix to "10" never changes it!  */
  1914.  
  1915. /* ARGSUSED */
  1916. static void
  1917. set_input_radix (args, from_tty, c)
  1918.      char *args;
  1919.      int from_tty;
  1920.      struct cmd_list_element *c;
  1921. {
  1922.   unsigned radix = *(unsigned *)c->var;
  1923.  
  1924.   if (from_tty)
  1925.     printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
  1926.     radix, radix, radix);
  1927. }
  1928. #endif
  1929.  
  1930. /* ARGSUSED */
  1931. static void
  1932. set_output_radix (args, from_tty, c)
  1933.      char *args;
  1934.      int from_tty;
  1935.      struct cmd_list_element *c;
  1936. {
  1937.   unsigned radix = *(unsigned *)c->var;
  1938.  
  1939.   if (from_tty)
  1940.     printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
  1941.     radix, radix, radix);
  1942.  
  1943.   /* FIXME, we really should be able to validate the setting BEFORE
  1944.      it takes effect.  */
  1945.   switch (radix)
  1946.     {
  1947.     case 16:
  1948.       output_format = 'x';
  1949.       break;
  1950.     case 10:
  1951.       output_format = 0;
  1952.       break;
  1953.     case 8:
  1954.       output_format = 'o';        /* octal */
  1955.       break;
  1956.     default:
  1957.       output_format = 0;
  1958.       error ("Unsupported radix ``decimal %d''; using decimal output",
  1959.           radix);
  1960.     }
  1961. }
  1962.  
  1963. /* Both at once */
  1964. static void
  1965. set_radix (arg, from_tty, c)
  1966.      char *arg;
  1967.      int from_tty;
  1968.      struct cmd_list_element *c;
  1969. {
  1970.   unsigned radix = *(unsigned *)c->var;
  1971.  
  1972.   if (from_tty)
  1973.     printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
  1974.     radix, radix, radix);
  1975.  
  1976.   input_radix = radix;
  1977.   output_radix = radix;
  1978.  
  1979.   set_output_radix (arg, 0, c);
  1980. }
  1981.  
  1982. struct cmd_list_element *setprintlist = NULL;
  1983. struct cmd_list_element *showprintlist = NULL;
  1984.  
  1985. /*ARGSUSED*/
  1986. static void
  1987. set_print (arg, from_tty)
  1988.      char *arg;
  1989.      int from_tty;
  1990. {
  1991.   printf (
  1992. "\"set print\" must be followed by the name of a print subcommand.\n");
  1993.   help_list (setprintlist, "set print ", -1, stdout);
  1994. }
  1995.  
  1996. /*ARGSUSED*/
  1997. static void
  1998. show_print (args, from_tty)
  1999.      char *args;
  2000.      int from_tty;
  2001. {
  2002.   cmd_show_list (showprintlist, from_tty, "");
  2003. }
  2004.  
  2005. void
  2006. _initialize_valprint ()
  2007. {
  2008.   struct cmd_list_element *c;
  2009.  
  2010.   add_prefix_cmd ("print", no_class, set_print,
  2011.           "Generic command for setting how things print.",
  2012.           &setprintlist, "set print ", 0, &setlist);
  2013.   add_alias_cmd ("p", "print", no_class, 1, &setlist); 
  2014.   add_alias_cmd ("pr", "print", no_class, 1, &setlist); /* prefer set print
  2015.                                                            to     set prompt */
  2016.   add_prefix_cmd ("print", no_class, show_print,
  2017.           "Generic command for showing print settings.",
  2018.           &showprintlist, "show print ", 0, &showlist);
  2019.   add_alias_cmd ("p", "print", no_class, 1, &showlist); 
  2020.   add_alias_cmd ("pr", "print", no_class, 1, &showlist); 
  2021.  
  2022.   add_show_from_set
  2023.     (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max,
  2024.           "Set limit on string chars or array elements to print.\n\
  2025. \"set print elements 0\" causes there to be no limit.",
  2026.           &setprintlist),
  2027.      &showprintlist);
  2028.  
  2029.   add_show_from_set
  2030.     (add_set_cmd ("pretty", class_support, var_boolean, (char *)&prettyprint,
  2031.           "Set prettyprinting of structures.",
  2032.           &setprintlist),
  2033.      &showprintlist);
  2034.  
  2035.   add_show_from_set
  2036.     (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint,
  2037.           "Set printing of unions interior to structures.",
  2038.           &setprintlist),
  2039.      &showprintlist);
  2040.   
  2041.   add_show_from_set
  2042.     (add_set_cmd ("vtbl", class_support, var_boolean, (char *)&vtblprint,
  2043.           "Set printing of C++ virtual function tables.",
  2044.           &setprintlist),
  2045.      &showprintlist);
  2046.  
  2047.   add_show_from_set
  2048.     (add_set_cmd ("array", class_support, var_boolean, (char *)&arrayprint,
  2049.           "Set prettyprinting of arrays.",
  2050.           &setprintlist),
  2051.      &showprintlist);
  2052.  
  2053.   add_show_from_set
  2054.     (add_set_cmd ("object", class_support, var_boolean, (char *)&objectprint,
  2055.       "Set printing of object's derived type based on vtable info.",
  2056.           &setprintlist),
  2057.      &showprintlist);
  2058.  
  2059.   add_show_from_set
  2060.     (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint,
  2061.           "Set printing of addresses.",
  2062.           &setprintlist),
  2063.      &showprintlist);
  2064.  
  2065. #if 0
  2066.   /* The "show radix" cmd isn't good enough to show two separate values.
  2067.      The rest of the code works, but the show part is confusing, so don't
  2068.      let them be set separately 'til we work out "show".  */
  2069.   c = add_set_cmd ("input-radix", class_support, var_uinteger,
  2070.            (char *)&input_radix,
  2071.           "Set default input radix for entering numbers.",
  2072.           &setlist);
  2073.   add_show_from_set (c, &showlist);
  2074.   c->function = set_input_radix;
  2075.  
  2076.   c = add_set_cmd ("output-radix", class_support, var_uinteger,
  2077.            (char *)&output_radix,
  2078.           "Set default output radix for printing of values.",
  2079.           &setlist);
  2080.   add_show_from_set (c, &showlist);
  2081.   c->function = set_output_radix;
  2082. #endif 
  2083.  
  2084.   c = add_set_cmd ("radix", class_support, var_uinteger,
  2085.            (char *)&output_radix,
  2086.           "Set default input and output number radix.",
  2087.           &setlist);
  2088.   add_show_from_set (c, &showlist);
  2089.   c->function.sfunc = set_radix;
  2090.  
  2091.   /* Give people the defaults which they are used to.  */
  2092.   prettyprint = 0;
  2093.   unionprint = 1;
  2094.   vtblprint = 0;
  2095.   arrayprint = 0;
  2096.   addressprint = 1;
  2097.   objectprint = 0;
  2098.  
  2099.   print_max = 200;
  2100.  
  2101.   /* Initialize the names of the various types based on their lengths on
  2102.      the target, in bits.  Note that ordering is important, so that for example,
  2103.      if ints and longs are the same size, that size will default to "int". */
  2104.  
  2105.   unsigned_type_table = (char **)
  2106.     xmalloc ((1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)) * sizeof (char *));
  2107.   bzero (unsigned_type_table, (1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)));
  2108.   unsigned_type_table[TARGET_CHAR_BIT/TARGET_CHAR_BIT] = "unsigned char";
  2109.   unsigned_type_table[TARGET_SHORT_BIT/TARGET_CHAR_BIT] = "unsigned short";
  2110.   unsigned_type_table[TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT] = "unsigned long long";
  2111.   unsigned_type_table[TARGET_LONG_BIT/TARGET_CHAR_BIT] = "unsigned long";
  2112.   unsigned_type_table[TARGET_INT_BIT/TARGET_CHAR_BIT] = "unsigned int";
  2113.  
  2114.   signed_type_table = (char **)
  2115.     xmalloc ((1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)) * sizeof (char *));
  2116.   bzero (signed_type_table, (1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)));
  2117.   signed_type_table[TARGET_CHAR_BIT/TARGET_CHAR_BIT] = "char";
  2118.   signed_type_table[TARGET_SHORT_BIT/TARGET_CHAR_BIT] = "short";
  2119.   signed_type_table[TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT] = "long long";
  2120.   signed_type_table[TARGET_LONG_BIT/TARGET_CHAR_BIT] = "long";
  2121.   signed_type_table[TARGET_INT_BIT/TARGET_CHAR_BIT] = "int";
  2122.  
  2123.   float_type_table = (char **)
  2124.     xmalloc ((1 + (TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT)) * sizeof (char *));
  2125.   bzero (float_type_table, (1 + (TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT)));
  2126.   float_type_table[TARGET_FLOAT_BIT/TARGET_CHAR_BIT] = "float";
  2127.   float_type_table[TARGET_DOUBLE_COMPLEX_BIT/TARGET_CHAR_BIT] = "double complex";
  2128.   float_type_table[TARGET_COMPLEX_BIT/TARGET_CHAR_BIT] = "complex";
  2129.   float_type_table[TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT] = "long double";
  2130.   float_type_table[TARGET_DOUBLE_BIT/TARGET_CHAR_BIT] = "double";
  2131.  
  2132.   obstack_begin (&dont_print_obstack, 32 * sizeof (struct type *));
  2133. }
  2134.